package com.device.operating.dao.impl;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.springframework.stereotype.Repository;

import com.device.operating.dao.EmRepository;
@Repository("EmRepository")
public class EmRepositoryImpl implements EmRepository{
	@PersistenceContext(unitName="spring.data.jpa.activiti")
	private EntityManager em;

	@Override
	public Query createQuery(String sql) {
		// TODO Auto-generated method stub
		return em.createQuery(sql);
	}

	@Override
	public Query createNativeQuery(String sql) {
		// TODO Auto-generated method stub
		return em.createNamedQuery(sql);
	}

	@Override
	public void SaveThisEntity(Object obj) {
		// TODO Auto-generated method stub
		em.persist(obj);
	}

	@Override
	public void updateThisEntity(Object obj) {
		// TODO Auto-generated method stub
		em.merge(obj);
	}

	@Override
	public void deleteThisEntity(Object obj) {
		// TODO Auto-generated method stub
        try {
            em.remove(em.merge(obj));
        } catch (RuntimeException re) {
            throw re;
        }
	}
}
